import React from 'react';
import Login from './src/page/login';
import Index from './src/page/home/index';
import RootNavigator from './src/test/stack';
import RootTabs from './src/test/Tab';
import RootDrawer from './src/test/DrawerNavigator';
import {Root, get, Loading} from './src/lib/components';
import SplashScreen from 'react-native-splash-screen'

export default class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {logined: false, user: false, loading: true};
    }

    componentDidMount() {
        const self = this;
        get('/admin/user/get_current')
            .then(res => {
                //self.props.login(res.data);
                if (res.code == 200) {
                    self.setState({user: res.data, loading: false})
                } else {
                    self.setState({loading: false})
                }
                SplashScreen.hide();
            })
            .catch(e => {
                console.log(e);
            })

    }

    render() {
        if (this.state.loading) {
            return <Loading/>;
        }
        // console.log(this.props.user);
        return (
            (!this.state.user) ? <Root><Login login={(data) => {
                this.setState({user: data})
            }}/></Root> : <Root><Index {...this.props.user}/></Root>
        );
    }
}
